package com.befiv.lock.redis;

import com.befiv.lock.modle.Redis;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.PostConstruct;

/**
 * @Author: Gjq
 * @Date: 2019/6/28 0028 上午 9:50
 */
public class RedissonConf {
    private RedissonClient redissonClient;
    @Autowired
    private Redis redis;
    public RedissonConf() {
    }
    @PostConstruct
    public void init(){
        Config config = new Config();
        config.useSingleServer().setAddress(redis.getHost()+":"+redis.getPort())
                .setDatabase(redis.getDatabase());
        if(redis.getPassword() != null){
            config.useSingleServer().setPassword(redis.getPassword());
        }
        redissonClient= Redisson.create(config);
    }
    public RedissonClient getClient(){
        return this.redissonClient;
    }

}
